/*
 * Created on 10.05.2006
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ro.qi.framework.sys.users.profile.entities;

import java.util.Hashtable;
import java.util.Vector;

import ro.qi.framework.sys.entities.Entity;

/**
 * @author Luiza Varovici
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class UsersAccountProfileQuestionCollection extends Entity{
	
	public UsersAccountProfileQuestionCollection() {
		super();
		select();
	}
	
	public int getNoQuestions() {
		return ((Vector)getValue("questions")).size();
	}
	
	public int getQuestionId(int index) {
		if( index < getNoQuestions() ) {
			Hashtable tmp = (Hashtable)(((Vector)getValue("questions")).get(index));
			if( tmp.containsKey("questionId") )
				return Integer.parseInt(tmp.get("questionId").toString());
		}
		return 0;
	}
	
	public UsersAccountProfileQuestion getQuestion(int index) {
		int questionId = getQuestionId(index);
		if( questionId > 0 )
			return new UsersAccountProfileQuestion(questionId);
		return null;
	}

	public UsersAccountProfileQuestion getFirstQuestion() {
		if( getNoQuestions() > 0 ) {
			UsersAccountProfileQuestion question = getQuestion(0);
			while( question.getPrevId() > 0 )
			question = new UsersAccountProfileQuestion(question.getPrevId());
			return question;
		}
		return null;
	}

	public UsersAccountProfileQuestion getLastQuestion() {
		if( getNoQuestions() > 0 ) {
			UsersAccountProfileQuestion question = getQuestion(0);
			while( question.getNextId() > 0 )
			question = new UsersAccountProfileQuestion(question.getNextId());
			return question;
		}
		return null;
	}
}



